﻿<!-- Copyright © LECO Corporation 2013.  All Rights Reserved. -->

<UserControl x:Class="CornerstoneRemoteControlClient.Views.DataViews.ConnectionDataView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:helpers="clr-namespace:CornerstoneRemoteControlClient.Helpers"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid Margin="15,5">
        
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="250"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel Grid.Row="0">

            <TextBlock Style="{StaticResource HeaderText16}" Margin="0,10,0,10">
                In order to access the Cornerstone remote capabilites, a connection must be established on the port on which Cornerstone is listening. The default port value is 12345, however, this can
                be changed within Cornerstone. Data sent over this connection to and from Cornerstone is in the form of XML. Each message is prepended with an integer value containing the number of bytes
                making up the message payload.
            </TextBlock>
            
            <TextBlock Text="{Binding ConnectionText}" Style="{StaticResource HeaderText16}" Margin="0,10,0,10"/>

        </StackPanel>

        <ScrollViewer Grid.Row="2" Background="Black" Margin="0,10" VerticalScrollBarVisibility="Auto">
            <ItemsControl ItemsSource="{Binding ConnectionViewModel.Traffic.ObservableCollection}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBox IsReadOnly="True" BorderThickness="0" Text="{Binding Data, Mode=OneWay}" Style="{StaticResource TrafficStyle}">
                        </TextBox>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>

        <Grid Grid.Row="1"> 
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width=".30*"/>
                <ColumnDefinition Width="2"/>
                <ColumnDefinition Width=".40*"/>
                <ColumnDefinition Width="2"/>
                <ColumnDefinition Width=".30*"/>
            </Grid.ColumnDefinitions>

            <Border CornerRadius="10" Background="Bisque" Grid.ColumnSpan="5" BorderBrush="DarkGray" BorderThickness="1"></Border>
            <Grid Grid.Column="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width=".65*"/>
                    <ColumnDefinition Width=".35*"/>
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="2"/>
                    <RowDefinition/>
                    <RowDefinition Height="20"/>
                </Grid.RowDefinitions>

                <!-- IP Address and Port controls -->
                <Grid VerticalAlignment="Center" Grid.Column="0" Grid.Row="0" Margin="5,0,5,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Column="0" Grid.Row="0" Text="IP Address:" Margin="2,1" HorizontalAlignment="Right"/>
                    <TextBlock Grid.Column="0" Grid.Row="1" Text="Port:" Margin="2,1" HorizontalAlignment="Right"/>

                    <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding ConnectionViewModel.IpAddress}" Margin="0,2,0,1"/>
                    <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding ConnectionViewModel.Port}" Margin="0,2,0,1"/>
                </Grid>

                <!-- Connect/Disconnect controls -->
                <StackPanel Grid.Column="1" Grid.Row="0" VerticalAlignment="Center">
                    <Button Content="Connect" Command="{Binding ConnectionViewModel.ConnectCommand}" Height="20" Width="85" Margin="5" IsEnabled="{Binding ConnectionViewModel.Connected, Converter={helpers:InverseBooleanConverter}}"/>
                    <Button Content="Disconnect" Command="{Binding ConnectionViewModel.DisconnectCommand}" Height="20" Width="85" Margin="5" IsEnabled="{Binding ConnectionViewModel.Connected}"/>
                </StackPanel>

                <Rectangle Fill="DarkGray" Grid.Row="1" Grid.ColumnSpan="2"/>

                <!-- Logon/off controls -->
                <Grid VerticalAlignment="Center" Grid.Column="0" Grid.Row="2" Margin="5,0,5,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Column="0" Grid.Row="0" Text="Cornerstone User Name:" Margin="2" HorizontalAlignment="Right"/>
                    <TextBlock Grid.Column="0" Grid.Row="1" Text="Password:" Margin="2" HorizontalAlignment="Right"/>

                    <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding ConnectionViewModel.Username}" Margin="0,2"/>
                    <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding ConnectionViewModel.Password}" Margin="0,2"/>
                </Grid>

                <TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" Text="{Binding ConnectionViewModel.LogOnResult}" Margin="7,2" Style="{StaticResource ErrorText}"/>

                <StackPanel Grid.Column="1" Grid.Row="2" VerticalAlignment="Center">
                    <Button Content="Log On" Command="{Binding ConnectionViewModel.LogonCommand}" Height="20" Width="85" Margin="5" IsEnabled="{Binding ConnectionViewModel.CanLogOn}"/>
                    <Button Content="Log Off" Command="{Binding ConnectionViewModel.LogoffCommand}" Height="20" Width="85" Margin="5" IsEnabled="{Binding ConnectionViewModel.CanLogOff}"/>
                </StackPanel>

            </Grid>

            <!-- Instrument Info controls -->
            <DockPanel Grid.Column="2" Grid.Row="0" Margin="5">
                <TextBlock Text="Connected Instrument Information:" DockPanel.Dock="Top" Style="{StaticResource HeaderText}"/>
                <ScrollViewer Margin="0,2,0,0" VerticalScrollBarVisibility="Auto">
                    <ItemsControl ItemsSource="{Binding ConnectionViewModel.InstrumentInfo.ObservableCollection}" HorizontalContentAlignment="Stretch">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width=".4*"/>
                                        <ColumnDefinition Width=".6*"/>
                                    </Grid.ColumnDefinitions>

                                    <TextBlock Text="{Binding Name}" TextAlignment="Left" Grid.Column="0"/>
                                    <TextBlock Text="{Binding Value}" TextAlignment="Left" Grid.Column="1" TextWrapping="Wrap"/>
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </DockPanel>

            <!-- Supported Languages controls -->
            <DockPanel Grid.Column="4" Grid.Row="0" Margin="5">
                <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
                    <TextBlock Text="Supported Cultures:" Style="{StaticResource HeaderText}"/>
                    <TextBlock Text="{Binding ConnectionViewModel.SelectedLanguage.Key}" Margin="5,0,2,0"/>
                    <TextBlock Text="{Binding ConnectionViewModel.SelectedLanguage.Name}" Margin="2,0"/>
                </StackPanel>
                <ScrollViewer Margin="0,2,0,0" VerticalScrollBarVisibility="Auto">
                    <ListBox ItemsSource="{Binding ConnectionViewModel.SupportedCultures.ObservableCollection}" SelectedItem="{Binding ConnectionViewModel.SelectedLanguage, Mode=TwoWay}" HorizontalContentAlignment="Stretch">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width=".4*"/>
                                        <ColumnDefinition Width=".6*"/>
                                    </Grid.ColumnDefinitions>

                                    <TextBlock Text="{Binding Key}" TextAlignment="Left" Grid.Column="0"/>
                                    <TextBlock Text="{Binding Name}" TextAlignment="Left" Grid.Column="1" TextWrapping="Wrap"/>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </ScrollViewer>
            </DockPanel>

            <!-- Separators -->
            <Rectangle Fill="DarkGray" Grid.Column="1" Grid.RowSpan="2"/>
            <Rectangle Fill="DarkGray" Grid.Column="3" Grid.RowSpan="2"/>

        </Grid>
    </Grid>
</UserControl>
